'use strict';

const Controller = require('egg').Controller;

class LoginController extends Controller {
  async index() {
    const { ctx } = this;
    var {username,pwd} = ctx.request.body
    var data = await ctx.model.User.find({username,pwd})
    if(data.length){
        ctx.cookies.set('username',username,{
            httpOnly:false
        })
        ctx.body={
            code:200,
            msg:'登录成功',
            username
        }
    }else{
        ctx.body={
            code:400,
            msg:'用户或密码错误'
        }
    }
  }
  
}

module.exports = LoginController;